package im.yisme.view.ui.animation;

import im.yisme.R;
import im.yisme.view.activities.MusicLibraryActivity;
import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.view.animation.Animation.AnimationListener;
import android.view.inputmethod.InputMethodManager;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;

public class MusicLibAnimationSet {
	//动画
	public Animation detailPaneZoomIn,detailPaneZoomOut,
                     listLeftOut,listLeftIn,
                     detailPaneRightOut,detailPaneRightIn,
                     importButtonBottomOut,importButtonBottomIn,
                     backButtonBottomOut,backButtonBottomIn,
                     titleFadeOut,titleFadeIn,
                     modifyPaneTopIn,modifyPaneTopOut;
	
	//音乐库界面组件
		private ListView list;
		private ViewGroup detailPane;
		private ImageButton importButton,backButton;
		private ImageView title;
	//修改界面组件
		private ViewGroup modifyPane;
		
	//组件坐标点
		private static final int FROM_LIST_X = 75;
		private static final int TO_LIST_X = -480;
		private static final int FROM_DETAIL_PANE_X = 450;
		private static final int TO_DETAIL_PANE_X = 1280;
		private static final int FROM_BACK_BUTTON_Y = 430;
		private static final int TO_BACK_BUTTON_Y = 730;
		private static final int FROM_IMPORT_BUTTON_Y = 435;
		private static final int TO_IMPORT_BUTTON_Y = 680;
		private static final int FROM_MODIFY_PANE_Y = -300;
		private static final int TO_MODIFY_PANE_Y = 50;

	
	    private Context context;
	    private MusicLibraryActivity activity;
	    
	public MusicLibAnimationSet(Context context,
			 					MusicLibraryActivity activity,
			 					ListView list,
			 					ViewGroup detailPane,
			 					ImageButton importButton,
			 					ImageButton backButton,
			 					ImageView title){
		this.context = context;
		this.activity = activity;
		this.list = list;
		this.detailPane = detailPane;
		this.importButton = importButton;
		this.backButton = backButton;
		this.title = title;

		
		initAnimations();
	}
	public void registerModifyPane(ViewGroup modifyPane){
		this.modifyPane = modifyPane;
	}
	private void initAnimations(){
		detailPaneZoomIn =AnimationUtils.loadAnimation(context, R.anim.detail_panel_zoomin);
		
		detailPaneZoomOut = AnimationUtils.loadAnimation(context, R.anim.detail_panel_zoomout);
        detailPaneZoomOut.setAnimationListener(new AnimationListener() {
			
			public void onAnimationStart(Animation animation) {}		
			public void onAnimationRepeat(Animation animation) {}
			
			public void onAnimationEnd(Animation animation) {
				// TODO Auto-generated method stub
				//updateInfo
				activity.updateDetailPaneInfo();
				detailPane.startAnimation(detailPaneZoomIn);
			}
		});
        
        listLeftOut = AnimationUtils.loadAnimation(context, R.anim.musiclib_list_left_out);
        listLeftOut.setAnimationListener(new AnimationListener() {
			
			public void onAnimationStart(Animation animation) {}		
			public void onAnimationRepeat(Animation animation) {}
			
			public void onAnimationEnd(Animation animation) {
				// TODO Auto-generated method stub
		         int top = list.getTop();
		         int width = list.getWidth();
		         int height = list.getHeight();
		         list.clearAnimation();
		         list.layout(TO_LIST_X, top, TO_LIST_X+width, top+height);
		         list.setVisibility(View.INVISIBLE);
			}
		});
        
        listLeftIn = AnimationUtils.loadAnimation(context, R.anim.musiclib_list_left_in);
        listLeftIn.setAnimationListener(new AnimationListener() {
			
        	public void onAnimationStart(Animation animation) {
        		list.setVisibility(View.INVISIBLE);
        		int top = list.getTop();
		        int width = list.getWidth();
		        int height = list.getHeight();
		        list.layout(TO_LIST_X, top, TO_LIST_X+width, top+height);
		        list.setVisibility(View.VISIBLE);
		        
        	}
            public void onAnimationRepeat(Animation animation) {}
			
			public void onAnimationEnd(Animation animation) {
				// TODO Auto-generated method stub
				int top = list.getTop();
		        int width = list.getWidth();
		        int height = list.getHeight();
		        list.clearAnimation();
		        list.layout(FROM_LIST_X, top, FROM_LIST_X+width, top+height);
			}		
		});
        
        detailPaneRightOut = AnimationUtils.loadAnimation(context, R.anim.musiclib_detail_panel_right_out);
        detailPaneRightOut.setAnimationListener(new AnimationListener() {
			
        	public void onAnimationStart(Animation animation) {}
            public void onAnimationRepeat(Animation animation) {}
			
			public void onAnimationEnd(Animation animation) {
				// TODO Auto-generated method stub
				int top = detailPane.getTop();
		        int width = detailPane.getWidth();
		        int height = detailPane.getHeight();
		        detailPane.clearAnimation();
		        detailPane.layout(TO_DETAIL_PANE_X, top, TO_DETAIL_PANE_X+width, top+height);
		        detailPane.setVisibility(View.INVISIBLE);
			}		
		});

        detailPaneRightIn = AnimationUtils.loadAnimation(context, R.anim.musiclib_detail_panel_right_in);
        detailPaneRightIn.setAnimationListener(new AnimationListener() {
			
        	public void onAnimationStart(Animation animation) {
        		detailPane.setVisibility(View.INVISIBLE);
        		int top = detailPane.getTop();
		        int width = detailPane.getWidth();
		        int height = detailPane.getHeight();
		        detailPane.layout(TO_DETAIL_PANE_X, top, TO_DETAIL_PANE_X+width, top+height);
		        detailPane.setVisibility(View.VISIBLE);
        	}
            public void onAnimationRepeat(Animation animation) {}
			
			public void onAnimationEnd(Animation animation) {
				// TODO Auto-generated method stub
				int top = detailPane.getTop();
		        int width = detailPane.getWidth();
		        int height = detailPane.getHeight();
		        detailPane.clearAnimation();
		        detailPane.layout(FROM_DETAIL_PANE_X, top, FROM_DETAIL_PANE_X+width, top+height);
			}		
		});

        importButtonBottomOut = AnimationUtils.loadAnimation(context, R.anim.musiclib_buttons_bottom_out);
        importButtonBottomOut.setAnimationListener(new AnimationListener() {
			
        	public void onAnimationStart(Animation animation) {}
            public void onAnimationRepeat(Animation animation) {}
			
			public void onAnimationEnd(Animation animation) {
				// TODO Auto-generated method stub
				int left = importButton.getLeft();
		        int width = importButton.getWidth();
		        int height = importButton.getHeight();
		        importButton.clearAnimation();
		        importButton.layout(left, TO_IMPORT_BUTTON_Y, left+width, TO_IMPORT_BUTTON_Y+height);
		        importButton.setVisibility(View.INVISIBLE);
			}		
		});

        importButtonBottomIn = AnimationUtils.loadAnimation(context, R.anim.musiclib_import_button_bottom_in);
        importButtonBottomIn.setAnimationListener(new AnimationListener() {
			
        	public void onAnimationStart(Animation animation) {
        		importButton.setVisibility(View.INVISIBLE);
        		int left = importButton.getLeft();
		        int width = importButton.getWidth();
		        int height = importButton.getHeight();
		        importButton.layout(left, TO_IMPORT_BUTTON_Y, left+width, TO_IMPORT_BUTTON_Y+height);
		        importButton.setVisibility(View.VISIBLE);
        	}
            public void onAnimationRepeat(Animation animation) {}
			
			public void onAnimationEnd(Animation animation) {
				// TODO Auto-generated method stub
				int left = importButton.getLeft();
		        int width = importButton.getWidth();
		        int height = importButton.getHeight();
		        importButton.clearAnimation();
		        importButton.layout(left, FROM_IMPORT_BUTTON_Y, left+width, FROM_IMPORT_BUTTON_Y+height);
			}		
		});

        backButtonBottomIn = AnimationUtils.loadAnimation(context, R.anim.musiclib_back_button_bottom_in);
        backButtonBottomIn.setAnimationListener(new AnimationListener() {
			
        	public void onAnimationStart(Animation animation) {
        		backButton.setVisibility(View.INVISIBLE);
        		int left = backButton.getLeft();
		        int width = backButton.getWidth();
		        int height = backButton.getHeight();
		        backButton.layout(left, TO_BACK_BUTTON_Y, left+width, TO_BACK_BUTTON_Y+height);
		        backButton.setVisibility(View.VISIBLE);
        	}
            public void onAnimationRepeat(Animation animation) {}
			
			public void onAnimationEnd(Animation animation) {
				// TODO Auto-generated method stub
				int left = backButton.getLeft();
		        int width = backButton.getWidth();
		        int height = backButton.getHeight();
		        backButton.clearAnimation();
		        backButton.layout(left, FROM_BACK_BUTTON_Y, left+width, FROM_BACK_BUTTON_Y+height);
		        
			}		
		});

        backButtonBottomOut = AnimationUtils.loadAnimation(context, R.anim.musiclib_buttons_bottom_out);
        backButtonBottomOut.setAnimationListener(new AnimationListener() {
			
        	public void onAnimationStart(Animation animation) {}
            public void onAnimationRepeat(Animation animation) {}
			
			public void onAnimationEnd(Animation animation) {
				// TODO Auto-generated method stub
				int left = backButton.getLeft();
		        int width = backButton.getWidth();
		        int height = backButton.getHeight();
		        backButton.clearAnimation();
		        backButton.layout(left, TO_BACK_BUTTON_Y, left+width, TO_BACK_BUTTON_Y+height);
		        backButton.setVisibility(View.INVISIBLE);
			}		
		});
        
        titleFadeOut = AnimationUtils.loadAnimation(context, R.anim.musiclib_title_fade_out);
        titleFadeOut.setAnimationListener(new AnimationListener() {
			
			public void onAnimationStart(Animation animation) {}
			public void onAnimationRepeat(Animation animation) {}
			
			public void onAnimationEnd(Animation animation) {
				// TODO Auto-generated method stub
				
			}
		});
        titleFadeIn = AnimationUtils.loadAnimation(context, R.anim.musiclib_title_fade_in);
        
        
        modifyPaneTopIn = AnimationUtils.loadAnimation(context, R.anim.musiclib_modify_panel_top_in);
        modifyPaneTopIn.setAnimationListener(new AnimationListener() {
			
        	public void onAnimationStart(Animation animation) {
        		modifyPane.setVisibility(View.INVISIBLE);
        		int left = modifyPane.getLeft();
		        int width = modifyPane.getWidth();
		        int height = modifyPane.getHeight();
		        modifyPane.layout(left, FROM_MODIFY_PANE_Y, left+width, FROM_MODIFY_PANE_Y+height);
		        modifyPane.setVisibility(View.VISIBLE);
        	}
            public void onAnimationRepeat(Animation animation) {}
			
			public void onAnimationEnd(Animation animation) {
				// TODO Auto-generated method stub
				int left = modifyPane.getLeft();
		        int width = modifyPane.getWidth();
		        int height = modifyPane.getHeight();
		        modifyPane.clearAnimation();
		        modifyPane.layout(left, TO_MODIFY_PANE_Y, left+width, TO_MODIFY_PANE_Y+height);
			}		
		});
        
        modifyPaneTopOut = AnimationUtils.loadAnimation(context, R.anim.musiclib_modify_panel_top_out);
        modifyPaneTopOut.setAnimationListener(new AnimationListener() {
			
        	public void onAnimationStart(Animation animation) {}
            public void onAnimationRepeat(Animation animation) {}
			
			public void onAnimationEnd(Animation animation) {
				// TODO Auto-generated method stub
				int left = modifyPane.getLeft();
		        int width = modifyPane.getWidth();
		        int height = modifyPane.getHeight();
		        modifyPane.clearAnimation();
		        modifyPane.layout(left, FROM_MODIFY_PANE_Y, left+width, FROM_MODIFY_PANE_Y+height);	
		        modifyPane.setVisibility(View.INVISIBLE);
			}		
		});
	}
}
